//统一管理项目用户相关的接口
import request from '@/utils/request'
import {
  UserLoginRequestData,
  UserLoginResponseData,
  UserInfoResponseData,
  UserInfoResponsePageData,
  UserInfoRecord,
} from './type'
//统一接口管理
enum API {
  //用户登陆接口
  UserLogin_URL = '/admin/acl/index/login ',
  //获取用户信息
  GetUserInfo_URL = '/admin/acl/index/info',
  //用户退出接口
  UserLoginOut_URL = '/admin/acl/index/logout',
  //获取用户信息分页数据
  GetUserPageInfo_URL = '/admin/acl/user/',
  //添加用户信息
  SaveUserInfo_URL = '/admin/acl/user/save',
  //修改用户信息
  UpdateUserInfo_URL = '/admin/acl/user/update',
}
//用户登陆接口
export const UserLogin = (data: UserLoginRequestData) =>
  request.post<any, UserLoginResponseData>(API.UserLogin_URL, data)
//获取用户信息
export const GetUserInfo = () =>
  request.get<any, UserInfoResponseData>(API.GetUserInfo_URL)
//用户退出接口
export const UserLoginOut = () => request.post<any, any>(API.UserLoginOut_URL)
//获取用户分页数据
export const GetUserPageData = (current: number, pageSize: number) =>
  request.get<any, UserInfoResponsePageData>(
    API.GetUserPageInfo_URL + current + '/' + pageSize,
  )
//添加或修改用户信息
export const UpdateOrSaveUser = (data: UserInfoRecord) => {
  //如果有Id
  if (data.id) {
    return request.put<any, any>(API.UpdateUserInfo_URL, data)
  } else {
    return request.post<any, any>(API.SaveUserInfo_URL, data)
  }
}
